package org.ljx.taobao.controller;

import org.ljx.taobao.api.IShoppingService;
import org.ljx.taobao.api.entity.Shopping;
import org.ljx.taobao.service.ShoppingServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: Ljx
 * @Date: 2021/12/31 11:56
 * @role: 购买商品
 */
@WebServlet("/commodity")
public class CommodityServlet extends HttpServlet {
    static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        String name = req.getParameter("names");
        String information = req.getParameter("informations");
        int price = Integer.parseInt(req.getParameter("prices"));
        int num = Integer.parseInt(req.getParameter("num"));
        Shopping shopping1 = new Shopping(name,information,price,num);
        IShoppingService iShoppingService = new ShoppingServiceImpl();
        x = iShoppingService.commodity(shopping1);
        resp.sendRedirect("panduan3.jsp");
    }
    public static boolean x(){
        return x;
    }
}

